package com.wistech.search.solr.bench.expression;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.math.RandomUtils;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.spel.support.StandardEvaluationContext;

import com.greenpineyu.fel.FelEngine;
import com.greenpineyu.fel.context.FelContext;

public class DefaultValue {
	private List<String> propteryNames;

	public DefaultValue(List<String> propteryNames) {
		this.propteryNames = propteryNames;
	}

	public Map<String, Object> getAviatorValues() {
		Map<String, Object> defaultValue = new HashMap<String, Object>(
				propteryNames.size());
		for (String property : propteryNames) {
			defaultValue.put(property, RandomUtils.nextFloat());
		}
		return defaultValue;
	}

	public FelContext getFelValues(FelEngine fel) {
		FelContext ctx = fel.getContext();
		for (String property : propteryNames) {
			ctx.set(property, RandomUtils.nextFloat());
		}
		return ctx;
	}

	public Map<String, Object> getJselValues() {
		Map<String, Object> defaultValue = new HashMap<String, Object>(
				propteryNames.size());
		for (String property : propteryNames) {
			defaultValue.put(property, RandomUtils.nextFloat());
		}
		return defaultValue;
	}

	public EvaluationContext getSpelValues() {
		StandardEvaluationContext ctx = new StandardEvaluationContext();
		for (String property : propteryNames) {
			ctx.setVariable(property, 0);
		}
		return ctx;
	}
}
